package com.gtt.pattern.structural.flyweight;

import java.util.HashMap;

/**
 * FlyweightFactory
 * 
 * @author 高甜甜(gao12581@sina.com)
 * @date 2011-3-31
 * 
 */
public class FlyweightFactory {

	private HashMap<String, Flyweight> elems = new HashMap<String, Flyweight>();

	public Flyweight getFlyweight(String name) {
		Flyweight flyweight = elems.get(name);
		if (flyweight == null) {
			flyweight = new ConcreteFlyweight(name);
			elems.put(name, flyweight);
		}
		return flyweight;
	}

	public int getFlyweightNumber() {
		return elems.size();
	}
}
